<?php
 
/*
 * Following code will list all the products
 */
 
// array for JSON response
$response = array();

if (isset($_POST['place_id'])){

	$place_id = $_POST['place_id']; 
 
	// include db connect class
	require_once __DIR__ . '/db_connect.php';
	 
	// connecting to db
	$db = new DB_CONNECT();
	 
	// get all products from products table

	$result = mysql_query("SELECT u.user_id_zing, u.user_name_zing, u.user_avatar_zing, c.* 
							FROM comment c
							INNER JOIN user u
								ON c.user_id_zing = u.user_id_zing
							WHERE type = '1' and place_id = '$place_id'
							ORDER BY c.comment_id desc") or die(mysql_error());
							
	 
	// check for empty result
	if (mysql_num_rows($result) > 0) {
		// looping through all results
		// products node
		$response["comment"] = array();
	 
		while ($row = mysql_fetch_array($result)) {
			// temp user array
			$comment = array();    
		
		$comment["comment_id"] = $row['comment_id'];
		$comment["user_id_zing"] = $row['user_id_zing'];
		$comment["user_name_zing"] = $row['user_name_zing'];
		$comment["user_avatar_zing"] = $row['user_avatar_zing'];
		$comment["detail_comment"] = $row['detail_comment'];
		$comment["time_comment"] = $row['time_comment'];
	 
			// push single product into final response array
			array_push($response["comment"], $comment);
		}
		// success
		$response["success"] = 1;
	 
		// echoing JSON response
		echo json_encode($response["comment"]);
	} else {
		// no products found
		$response["success"] = 0;
		$response["message"] = "No products found";
	 
		// echo no users JSON
		echo json_encode($response);
	}
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
 
    // echoing JSON response
    echo json_encode($response);
}
?>